import FastClick from 'fastclick'

FastClick(document.body)
/**
 * rem响应式方案的实现
 */
const doc = window.document
const baseWidth = 750
const documentHTML = doc.documentElement
let pixelRatio = 2

function setRootFont() {
  const docWidth = documentHTML.getBoundingClientRect().width
  const scale = docWidth / baseWidth
  let setSize = scale * 100
  documentHTML.style.fontSize = `${setSize}px`
  const realSize = parseFloat(window.getComputedStyle(document.documentElement).fontSize)
  // android webview 里 html font-size 因设置系统字体大小受到影响
  if (realSize != parseFloat(setSize.toFixed(4))) {
    setSize = (setSize * setSize) / realSize
    documentHTML.style.fontSize = `${setSize}px`
  }
  pixelRatio = window.devicePixelRatio === 3 ? 3 : 2
  documentHTML.setAttribute('data-dpr', pixelRatio + '')
}

setRootFont()
window.addEventListener('resize', setRootFont, false)
